package lexer

type TokenType string

// 定义一个Token结构体，包含类型、字面值和行号三个字段
type Token struct {
	Type    TokenType // 类型
	Literal string    // 字面值
	Line    int       // 行号
}

const (
	// ILLEGAL represents an illegal token
	ILLEGAL = "ILLEGAL"
	// EOF represents the end of the file
	EOF = "EOF"

	IDENT  = "IDENT"  // 标识符
	INT    = "INT"    // 整数
	FLOAT  = "FLOAT"  // 浮点数
	STRING = "STRING" // 字符串

	// 赋值运算符
	ASSIGN = "="
	// 加法运算符
	PLUS = "+"
	// 减法运算符
	MINUS = "-"
	// 乘法运算符
	ASTERISK = "*"
	// 除法运算符
	SLASH = "/"

	//==== start 比较运算符 ====//
	BANG     = "!"  //取反
	EQ       = "==" //等于
	NOT_EQ   = "!=" //不等于
	LT       = ">"  //大于
	GT       = "<"  //小于
	LARGE_GT = ">=" //大于等于
	SMALL_GT = "<=" //小于等于
	//==== start 比较运算符 ====//

	LPAREN    = "("
	RPAREN    = ")"
	LBRACKET  = "["
	RBRACKET  = "]"
	LBRACE    = "{"
	RBRACE    = "}"
	SQ        = "'"  //单引号
	DQ        = "\"" //双引号
	SEMICOLON = ";"

	//关键字
	LET      = "LET"   //定义变量
	TRUE     = "TRUE"  //真
	FALSE    = "FALSE" //假
	IF       = "IF"
	ELSE     = "ELSE"
	FOR      = "FOR"
	BREAK    = "BREAK"
	RETURN   = "RETURN"
	FUNCTION = "FUNCTION" //函数
	IMPORT   = "IMPORT"   //导入文件
	CLASS    = "CLASS"    //类
)

// 关键字列表
var keywords = map[string]TokenType{
	"let":   "LET",
	"true":  "TRUE",
	"false": "FALSE",
	"if":    "IF",

	"else": "ELSE",

	"for":    "FOR",
	"return": "RETURN",
	"func":   "FUNC",
}

// LookupIdent 函数用于查找标识符的类型
func LookupIdent(ident string) TokenType {
	// 在关键字表中查找标识符
	if tok, ok := keywords[ident]; ok {
		// 如果找到，返回关键字类型
		return tok
	}
	// 如果没有找到，返回标识符类型
	return IDENT
}
